package codebush.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.servlet.ModelAndView;

import codebush.domain.Users;
import codebush.service.Get;
import codebush.service.Home;

/**
 *2008-5-6
 *@author Fution Bai
 * Copyright 2007 
 */

@Controller
@RequestMapping("/profile/fill")
public class ProfileFillController {
	
	private final Get get;
	private final Home home;
	
	@Autowired
	public ProfileFillController(Get get, Home home){
		this.get = get;
		this.home = home;
	}
	
	public Get getGet(){
		return get;
	}
	
	public Home getHome(){
		return home;
	}
	
	/**
	 * 完善用户的个人信息/ fully fill the user's information
	 * 
	 * @param userId
	 * @return
	 */
	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView profileFill(@RequestParam(value = "uid")int userId) {
		ModelAndView mav = new ModelAndView();
		Users user = this.getGet().getUser(userId);
		mav.addObject("user", user);
		mav.setViewName("/profile_fill");
		return mav;
	}

	/**
	 * 完善用户的个人信息/ fully fill the user's information
	 * 
	 * @param userId
	 * @return
	 */
	@RequestMapping(method = RequestMethod.POST)
	public String processSubmit(@ModelAttribute("users") Users user, SessionStatus status) {
		this.getHome().profileFill(user);
		return "redirect:../profile?uid="+user.getId();
	}
}


